CC          = gcc
CC1         = gcc
CFLAGS	    = -fPIC -shared -o2
#CFLAGS	    = -fPIC -shared -o2 -D__MACOSX__
MKDIR       = mkdir -p
RM          = rm -f
CP          = cp -fp
ECHO        = echo
FIND        = find
MV          = mv -f
LN          = ln -s
AR          = ar -rv 
LFLAGS 	   :=  

LDLIBS     := -L. -lssl -lcrypto -lstdc++ 
DEBUG       = debug			
MKEY_SHARED = libmkey_ios.so
MKEY_STATIC = libmkey_ios.a
DEBUGFLAG   = -g -D_DEBUG

MOBLEX_DEVELOPMENT := ../mkey
K3_GM_DEVELOPMENT  := ../middleware

INC_FLAG = -I$(MOBLEX_DEVELOPMENT) \
		-I$(MOBLEX_DEVELOPMENT)/cert \
		-I$(MOBLEX_DEVELOPMENT)/mHAL/include \
		-I$(MOBLEX_DEVELOPMENT)/mHAL/include/mbedtls \
		-I$(MOBLEX_DEVELOPMENT)/mHAL/include/mbedtls/Threshold/include \
		-I$(MOBLEX_DEVELOPMENT)/sys \
		-I$(K3_GM_DEVELOPMENT) \
		-I$(K3_GM_DEVELOPMENT)/apdu/apdu.algo \
		-I$(K3_GM_DEVELOPMENT)/apdu/apdu.core \
		-I$(K3_GM_DEVELOPMENT)/apdu/apdu.def \
		-I$(K3_GM_DEVELOPMENT)/apdu/apdu.lib \
		-I$(K3_GM_DEVELOPMENT)/devmgr	\
		-I$(K3_GM_DEVELOPMENT)/gm_api \
		-I$(K3_GM_DEVELOPMENT)/k3gm/gm_api \
		-I$(K3_GM_DEVELOPMENT)/k3gm/gm_data_mgr \
		-I$(K3_GM_DEVELOPMENT)/mk_lib \
		-I$(K3_GM_DEVELOPMENT)/os \
		-I$(K3_GM_DEVELOPMENT)/polarssl \
		-I../


OBJ :=  $(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/apdu/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/cmd/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mFS/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/sys/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/Utils/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/drv/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/alg/alg/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/alg/alg_pr/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/hal/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/include/mbedtls/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/include/mbedtls/Threshold/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/cert/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/polarssl/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/apdu/apdu.algo/*.c))\
		$(patsubst %.c,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/os/mkey/*.c))
		

OBJ1 := $(patsubst %.cpp,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/mHAL/include/mbedtls/Threshold/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(MOBLEX_DEVELOPMENT)/cert/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/apdu/apdu.lib/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/apdu/apdu.core/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/k3gm/gm_api/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/k3gm/gm_data_mgr/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/mk_lib/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/mtoken_gm/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/devmgr/*.cpp))\
		$(patsubst %.cpp,%.o,$(wildcard $(K3_GM_DEVELOPMENT)/devmgr/virtual_dev/*.cpp))

	
all: $(OBJ) $(OBJ1)
	$(AR) $(MKEY_STATIC) $^  
	$(CC) $(CFLAGS) $(DEBUGFLAG) $(LFLAGS) $(LDLIBS) $^ -o  $(MKEY_SHARED) 

	 
#debug:$(OBJ) $(OBJ1)
#	$(AR) $(MKEY_STATIC) $^ 
#	$(CC) $(CFLAGS) $(DEBUGFLAG) $(LFLAGS) $(LDLIBS) $^ -o  $(MKEY_SHARED) 


$(OBJ) : %.o : %.c
	$(CC) $(CFLAGS) $(DEBUGFLAG)  -c  $(INC_FLAG) $< -o $@ 

$(OBJ1) : %.o : %.cpp
	$(CC1) $(CFLAGS) $(DEBUGFLAG)  -c  $(INC_FLAG) $< -o $@ 

clean:
	$(RM) $(OBJ) $(OBJ1) $(MKEY_SHARED) $(MKEY_STATIC)
